package leecode

func checkSymmetricTree(root *TreeNode) bool {
	if root == nil {
		return true
	}
	var compare func(left *TreeNode, right *TreeNode) bool
	compare = func(left *TreeNode, right *TreeNode) bool {
		if left == nil && right == nil {
			return true
		}
		if (left == nil && right != nil) || (left != nil && right == nil) {
			return false
		}
		if left.Val != right.Val {
			return false
		}
		//递归调用compare , 左子树的左 右子树的右
		resultLeft := compare(left.Left, right.Right)
		resultRight := compare(left.Right, right.Left)
		return resultLeft && resultRight
	}
	return compare(root.Left, root.Right)
}
